<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 复选框 -->
    <div>
      <label><input type="checkbox" name="choice" /></label>全选 <label><input type="checkbox" name="choice" /> </label>吃 <label><input type="checkbox" name="choice" /> </label>睡 <label><input type="checkbox" name="choice" /></label>学习
      <button onclick="allCheck('choice',true)">全选</button>
      <button onclick="allCheck('choice',false)">全不选</button>
      <button onclick="reserveCheck('choice')">反选</button>
    </div>
    <script>
      //全选和全不选
      function allCheck(name, boolValue) {
        var allvalue = document.getElementsByName(name)
        //遍历判断
        for (var i = 0; i < allvalue.length; i++) {
          if (allvalue[i].type == 'checkbox') allvalue[i].checked = boolValue
        }
      }
      //反选
      function reserveCheck(name) {
        var revalue = document.getElementsByName(name)
        //遍历判断
        for (i = 0; i < revalue.length; i++) {
          if (revalue[i].checked == true) revalue[i].checked = false
          else revalue[i].checked = true
        }
      }
    </script>
  </body>
</html>
